package org.apogee.mil.client.portal.pages;

import java.util.ArrayList;

import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.google.gwt.user.client.Element;

public class DebugForm extends LayoutContainer {

	private FormData data;
	private TextArea debugWindow;


	@Override  
	protected void onRender(Element parent, int index) {  
		super.onRender(parent, index);  
		createForm();  
		layout();
	}

	private void createForm() {
		data = new FormData("100%");

		FormPanel panel = new FormPanel();
		panel.setHeading("Debug Window");
		panel.setFieldWidth(1);
		panel.setAutoWidth(true);
		panel.setHideLabels(true);

		debugWindow = new TextArea();
		debugWindow.setHeight(400);
		debugWindow.setReadOnly(true);
		debugWindow.setValue("");

		panel.add(debugWindow, data);


		add(panel);

	}

	public void addMessage(String message) {
		if (debugWindow.getValue() == null) {
			debugWindow.setValue(message);
		} else {
			debugWindow.setValue(debugWindow.getValue() + "\n" + message);
		}
	}
	
	public void printBaseModels(ArrayList<BaseModel> models) {
		for (BaseModel bm : models) {
			for (String s : bm.getPropertyNames()) {
				addMessage("Property " + s + " Value: " + bm.get(s));
			}
		}
	}
}
